package com.yitongmao.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yitongmao.bean.SubmitIndentBean;
import com.yitongmao.yitmfruit.R;

import java.util.List;

import static com.yitongmao.yitmfruit.R.id.mFruitNum;
import static com.yitongmao.yitmfruit.R.id.mFruitPrice;
import static com.yitongmao.yitmfruit.R.id.mFruitone;

/*
* 作者：梁伟航 on 2017/8/10 19:07
* 类的用途：
*/
public class PlaceOrderActivityAdapter extends BaseAdapter {
    private Context context;
    private List<SubmitIndentBean.OrderListBean> orderList;

    public PlaceOrderActivityAdapter(Context context, List<SubmitIndentBean.OrderListBean> orderList) {
        this.context = context;
        this.orderList = orderList;
    }

    @Override
    public int getCount() {
        return orderList.size();
    }

    @Override
    public Object getItem(int position) {
        return orderList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.confitcrderlistviewitem, null);
            viewHolder.mFruitone = (ImageView) convertView.findViewById(mFruitone);
            viewHolder.mFruitNum = (TextView) convertView.findViewById(mFruitNum);
            viewHolder.mFruitName = (TextView) convertView.findViewById(R.id.mFruitName);
            viewHolder.mFruitDanjia = (TextView) convertView.findViewById(R.id.mFruitDanjia);
            viewHolder.mLuiyan = (EditText) convertView.findViewById(R.id.mLuiyan);
            viewHolder.mFruitPrice = (TextView) convertView.findViewById(mFruitPrice);
            convertView.setTag(viewHolder);//绑定ViewHolder对象
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(orderList.get(position).orderGoods.get(0).goodsThumb).into(viewHolder.mFruitone);
        viewHolder.mFruitNum.setText("X" + orderList.get(position).orderGoods.get(0).number);
        int number = orderList.get(0).orderGoods.get(0).number;
        double tradePrice = orderList.get(position).orderGoods.get(0).tradePrice;
        //double sumv = number * tradePrice;
        viewHolder.mFruitPrice.setText(String.valueOf(tradePrice));
        viewHolder.mFruitName.setText(orderList.get(position).orderGoods.get(0).title);
        viewHolder.mFruitDanjia.setText("￥" + tradePrice);
        return convertView;
    }
    class ViewHolder {
        public ImageView mFruitone;
        public TextView mFruitNum;
        public TextView mFruitName;
        public TextView mFruitDanjia;
        public EditText mLuiyan;
        public TextView mFruitPrice;
    }

}
